package com.lyf.auth.constant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.lyf.common.api.IErrorCode;
import lombok.Getter;

import java.util.HashMap;

@Getter
public enum ResponseCodeEnum implements IErrorCode {
   RESPONSE_CODE_SUCCESS("success", 0),
   RESPONSE_CODE_BUSY("busy", 29001),
   RESPONSE_CODE_NOT_SUPPORT("not support", 29002),
   RESPONSE_CODE_INVALID_CONF("invalid conf", 29003),
   RESPONSE_CODE_INVALID_PARAMETER("invalid parameter", 29101),
   RESPONSE_CODE_BUTT("RESPONSE_CODE_BUTT", 29999),
   RESPONSE_INSERT_DATA_ALREADY_EXISTS("insert data already exists in database", 29064),
   RESPONSE_CODE_EXCEPTION("unexcepted exception", 29003),
   RESPONSE_CODE_ERROR("error", 29900),
   NO_PERMISSION("无权限或未配置", 16001),
   SYSTEM_ERROR("系统故障", 16002),
   SUPPLIER_RSP_FAILED("调用供应商操作返回失败", 16003),
   PART_FAILED("部分失败", 16004),
   SUPPLIER_TIMEOUT("系统超时", 16005),
   RESOURCE_UNAVALIABLE("资源耗尽", 16006),
   NOT_EXIST("请求资源不存在", 16007),
   ALREADY_EXIST("请求资源已存在，请勿重复添加", 16008),
   NOT_READY("请求资源未准备好，请稍后重试", 16009),
   QUOTA_OVERFLOW("超过频率限制, 请稍后重试", 16010),
   DIRTY_WORDS("含有敏感词, 请过滤后发送", 16011),
   QUOTA_EMPTY("服务套餐余量不足, 请联系管理员", 16012),
   BLACK_LIST("接收方在黑名单中", 16013),
   ALL_FAILED("全部失败", 16014),
   FREQ_KEY_ERROR("内部错误:错误的频率限制的key", 16015),
   FREQ_ON("触发频率限制", 16016),
   HTTP_ERROR("HTTP请求失败", 16017),
   RESPONSE_CODE_TOKEN_NO_PERMISSION("无权限访问", 16018),
   RESPONSE_CODE_TOKEN_TIME_EXPIRED("Token expired", 16019),
   RESPONSE_CODE_TOKEN_INVALID("Token invalid", 16020),


   ;

   private static HashMap<Integer, ResponseCodeEnum> map = new HashMap();
   private String msg;
   private int code;

   private ResponseCodeEnum(String msg, int code) {
      this.msg = msg;
      this.code = code;
   }

   @JsonCreator
   public static ResponseCodeEnum fromValue(Integer protocolValue) {
      if (null == protocolValue) {
         return RESPONSE_CODE_BUTT;
      } else {
         ResponseCodeEnum codeEnum = (ResponseCodeEnum)map.getOrDefault(protocolValue, RESPONSE_CODE_BUTT);
         return codeEnum;
      }
   }


   static {
      ResponseCodeEnum[] var0 = values();
      int var1 = var0.length;

      for(int var2 = 0; var2 < var1; ++var2) {
         ResponseCodeEnum responseCodeEnum = var0[var2];
         map.put(responseCodeEnum.getCode(), responseCodeEnum);
      }

   }

   @Override
   public int getCode() {
      return code;
   }

   @Override
   public String getMsg() {
      return msg;
   }
}
